﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;

namespace WebApplication2
{
    public class XcActionFilter : IActionFilter
    {
        public void OnActionExecuting(ActionExecutingContext context)
        {
            if (!context.ModelState.IsValid)
            {
                //XcHttpResult result = new XcHttpResult() { Result = false };
                var log = "";
                foreach (var item in context.ModelState.Values)
                {
                    foreach (var error in item.Errors)
                    {
                        log += error.ErrorMessage + "|";
                    }
                }

                context.Result =  new ObjectResult(new { log });
            }
        }

        public void OnActionExecuted(ActionExecutedContext context)
        {

        }
    }
}
